package com.zhuiyun.educations.api.learningrecord.mapper;

import com.zhuiyun.educations.api.learningrecord.entity.DTO.LearningRecordEntityDTO;
import com.zhuiyun.educations.api.learningrecord.entity.LearningRecordEntity;
import com.zhuiyun.educations.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @ClassName LearningRecordMapper
 * @Description TODO
 * @Author cjl
 * @Date 2023/6/26 16:44
 **/
@Mapper
public interface LearningRecordMapper extends BaseMapper<LearningRecordEntity> {
    @Select("SELECT\n" +
            "\tcourse_info.*,\n" +
            "\tteacher.t_name,\n" +
            "\tteacher.image_id teacher_image_id, \n" +
            "\t`subject`.subject_type,\n" +
            "\tlearning_record.create_time time\n" +
            "FROM\n" +
            "\tlearning_record\n" +
            "\tLEFT JOIN course_info ON learning_record.course_id = course_info.id\n" +
            "\tLEFT JOIN teacher ON course_info.teacher_id = teacher.id\n" +
            "\tLEFT JOIN course ON course_info.course_id = course.id\n" +
            "\tLEFT JOIN `subject` ON course.subject_id = `subject`.id\n" +
            "WHERE\n" +
            "  learning_record.del_flag = 0\n" +
            "\tAND learning_record.user_id = #{userId}\n" +
            "\tAND course_info.del_flag = 0\n" +
            "\tAND course_info.course_status = 0\n" +
            "ORDER BY time DESC")
    List<LearningRecordEntityDTO> selectLearningRecordDTOByUserId(Integer userId);
}
